<template>
  <!-- 竞拍市场  规则设置 -->
  <div class="app-container">
    <el-descriptions class="margin-top" :labelStyle="{width:'150px',fontWeight:'bold',color:'#333'}" title="竞拍市场设置" :column="1" size="big" border>
      <el-descriptions-item label="再次开通虞豆">
        <el-input-number @change="saveData('againCost',againCost)" v-model="againCost" :step="500" style="width: 150px;" placeholder="再次开通的虞豆数量"></el-input-number>
        <div style="margin-top:5px;color:#999">
          <span>被系统关闭交易权限的店铺，再次开通时需要的虞豆数量，请填数字。</span><br />
        </div>
      </el-descriptions-item>
      <el-descriptions-item label="出价超时小时数">
        <el-input-number @change="saveData('bidTimeOut',bidTimeOut)" v-model="bidTimeOut" :step="12" style="width: 150px;" placeholder="出价超时小时数"></el-input-number>
        <div style="margin-top:5px;color:#999">
          <span>从发布竞拍到停止出价的时间，填写多少个小时，请填数字。</span><br />
        </div>
      </el-descriptions-item>
      <el-descriptions-item label="接受超时小时数">
        <el-input-number @change="saveData('acceptTimeOut',acceptTimeOut)" v-model="acceptTimeOut" :step="12" style="width: 150px;" placeholder="接受超时小时数"></el-input-number>
        <div style="margin-top:5px;color:#999">
          <span>从发布竞拍到接受报价的时间，填写多少个小时，请填数字。</span><br />
        </div>
      </el-descriptions-item>
      <el-descriptions-item label="报价时间">
        <el-time-select @change="saveData('baojiaTime',baojiaTime)" placeholder="起始时间" v-model="baojiaTime.startTime" style="width: 120px;" :picker-options="{
            start: '00:00',
            step: '00:30',
            end: '23:59'
          }">
        </el-time-select>
        -
        <el-time-select @change="saveData('baojiaTime',baojiaTime)" placeholder="结束时间" v-model="baojiaTime.endTime" style="width: 120px;" :picker-options="{
           start: '00:00',
            step: '00:30',
            end: '23:59',
            minTime: baojiaTime.startTime
          }">
        </el-time-select>
        <div style="margin-top:5px;color:#999">
          <span>允许号商报价的时间段，请选择时间段。</span><br />
        </div>
      </el-descriptions-item>

    </el-descriptions>
    <div style="line-height: 40px;color: red;margin-top: 15px;">以下规则为清退规则，店铺只要满足一条的，系统将会在次月自动关闭竞拍功能。</div>
    <el-descriptions class="margin-top" :labelStyle="{width:'150px',fontWeight:'bold',color:'#333'}" title="竞拍市场规则" :column="1" size="big" border>
      <el-descriptions-item label="买家中标成交率">
        <div>
          一个自然月内，中标成交率低于
          <el-input-number @change="saveData('买家规则1',zbcjlMin)" :controls="false" v-model="zbcjlMin" style="width: 100px;"></el-input-number>%
        </div>

        <div style="margin-top:5px;color:#999">
          <span>中标后取消订单的数量/总中标数量</span><br />
        </div>
      </el-descriptions-item>
      <el-descriptions-item label="买家未报价天数">
        <div>
          一个自然月内，未报价天数超过
          <el-input-number @change="saveData('买家规则2',weibaojiaDay)" :controls="false" v-model="weibaojiaDay" style="width: 100px;"></el-input-number>天
        </div>
        <div style="margin-top:5px;color:#999">
          <span>未报价天数是指这一天一个报价都没有提交。</span><br />
        </div>
      </el-descriptions-item>
      <el-descriptions-item label="卖家发布竞拍数量">
        <div>
          一个自然月内，发布少于<el-input-number @change="saveData('卖家规则1',fabuMinnumDays)" :controls="false" v-model="fabuMinnumDays.goodsNum" style="width: 100px;"></el-input-number>
          个竞拍商品的天数，超过<el-input-number @change="saveData('卖家规则1',fabuMinnumDays)" :controls="false" v-model="fabuMinnumDays.dayNum" style="width: 100px;"></el-input-number>天
        </div>
        <!-- <div style="margin-top:5px;color:#999">
          <span>从发布竞拍到接受报价的时间，填写多少个小时，请填数字。</span><br />
        </div> -->
      </el-descriptions-item>
      <el-descriptions-item label="卖家接受报价">
        <div>
          一个自然月内，报价人数多于<el-input-number @change="saveData('卖家规则2',bjPtimes)" :controls="false" v-model="bjPtimes.personNum" style="width: 100px;"></el-input-number>
          人的商品且未接受报价，超过<el-input-number @change="saveData('卖家规则2',bjPtimes)" :controls="false" v-model="bjPtimes.times" style="width: 100px;"></el-input-number>次
        </div>
        <!-- <div style="margin-top:5px;color:#999">
          <span>从发布竞拍到接受报价的时间，填写多少个小时，请填数字。</span><br />
        </div> -->
      </el-descriptions-item>
      <el-descriptions-item label="卖家成交率">
        <div>
          一个自然月内，接受报价后不成交的商品超过接受报价商品的
          <el-input-number @change="saveData('卖家规则3',cancelOrderBFB)" :controls="false" v-model="cancelOrderBFB" style="width: 100px;"></el-input-number>%
        </div>
        <!-- <div style="margin-top:5px;color:#999">
          <span>从发布竞拍到接受报价的时间，填写多少个小时，请填数字。</span><br />
        </div> -->
      </el-descriptions-item>
    </el-descriptions>
  </div>
</template>
  
  <script>
import jingpaiApi from "@/api/jingpaishichang/index.js";
import { getDicts, updateData } from "@/api/system/dict/data";
export default {
  name: "",
  components: {},
  data() {
    return {
      loading: false,
      jjscguize: {},

      againCost: "", //再次开通 虞豆数量
      bidTimeOut: "", //出价超时小时
      acceptTimeOut: "", //接受报价 超时时间  小时
      baojiaTime: {
        startTime: "",
        endTime: "",
      }, //报价时间

      zbcjlMin: "", //一个自然月内，中标成交率低于 x%
      weibaojiaDay: "", //一个自然月内，未报价天数超过 x 天
      fabuMinnumDays: {
        goodsNum: "",
        dayNum: "",
      }, //一个自然月内，发布少于 x 个竞拍商品超过 x 天的。 用逗号分隔填写

      bjPtimes: {
        personNum: "",
        times: "",
      }, //一个自然月内，报价人数多于 x 人的商品且未接受报价 超过 x 次的 。 用逗号分隔填写
      cancelOrderBFB: "", //一个自然月内，接受报价后不成交的商品超过接受报价商品的 x%
    };
  },
  computed: {
    userInfo() {
      return this.$store.getters.userInfo;
    },
    shopInfo() {
      return this.$store.getters.shopInfo;
    },
    allGameList() {
      return this.$store.getters.allGameList;
    },
  },
  created() {
    this.getJJSCguize();
  },
  activated() {
    // this.getList();
  },
  methods: {
    // 数据改变  保存字典数据
    saveData(key, data) {
      const obj = this.jjscguize[key];
      if (obj) {
        if(key=='baojiaTime'){
          obj.dictValue =  this.baojiaTime.startTime+','+this.baojiaTime.endTime
        }else if(key=='卖家规则1'){
          obj.dictValue =  this.fabuMinnumDays.goodsNum+','+this.fabuMinnumDays.dayNum
        }else if(key=='卖家规则2'){
          obj.dictValue =  this.bjPtimes.personNum+','+this.bjPtimes.times
        }else{
          obj.dictValue = data
        }
        updateData(obj).then((res) => {
          this.$message.success("保存成功！");
          this.getJJSCguize();
        });
      }
    },
    //获取竞价回收规则字典
    async getJJSCguize() {
      const res = await this.getDicts("biddingRule");
      if (res.data && res.data.length) {
        this.jjscguize = this.arrayToObject(res.data, "dictLabel");
        if (this.jjscguize.acceptTimeOut) {
          // 接受报价超时时间
          this.acceptTimeOut = this.jjscguize.acceptTimeOut.dictValue;
        }
        if (this.jjscguize.againCost) {
          // 再次开通虞豆
          this.againCost = this.jjscguize.againCost.dictValue;
        }
        if (this.jjscguize.baojiaTime) {
          // 报价超时时间
          const baojiaTime = this.jjscguize.baojiaTime.dictValue;
          if (baojiaTime && baojiaTime.includes(",")) {
            this.baojiaTime.startTime = baojiaTime.split(",")[0];
            this.baojiaTime.endTime = baojiaTime.split(",")[1];
          }
        }
        if (this.jjscguize.bidTimeOut) {
          // 出价超时时间
          this.bidTimeOut = this.jjscguize.bidTimeOut.dictValue;
        }
        if (this.jjscguize["买家规则1"]) {
          // 买家规则1 一个自然月内，中标成交率低于 x%
          this.zbcjlMin = this.jjscguize["买家规则1"].dictValue;
        }
        if (this.jjscguize["买家规则2"]) {
          // 买家规则 一个自然月内，未报价天数超过 x 天
          this.weibaojiaDay = this.jjscguize["买家规则2"].dictValue;
        }
        if (this.jjscguize["卖家规则1"]) {
          // 一个自然月内，发布少于 x 个竞拍商品超过 x 天的。 用逗号分隔填写
          const guize3 = this.jjscguize["卖家规则1"].dictValue;
          if (guize3 && guize3.includes(",")) {
            this.fabuMinnumDays.goodsNum = guize3.split(",")[0];
            this.fabuMinnumDays.dayNum = guize3.split(",")[1];
          }
        }
        if (this.jjscguize["卖家规则2"]) {
          // 一个自然月内，发布少于 x 个竞拍商品超过 x 天的。 用逗号分隔填写
          const guize4 = this.jjscguize["卖家规则2"].dictValue;
          if (guize4 && guize4.includes(",")) {
            this.bjPtimes.personNum = guize4.split(",")[0];
            this.bjPtimes.times = guize4.split(",")[1];
          }
        }
        if (this.jjscguize["卖家规则3"]) {
          // 买家规则 一个自然月内，未报价天数超过 x 天
          this.cancelOrderBFB = this.jjscguize["卖家规则3"].dictValue;
        }
      }
    },
  },
};
</script>
  <style lang="scss" scoped>
</style>
  